import json

import pandas as pd

txtfile = open(r"D:\Chrome_download\Correted-ProgrammableWeb-dataset-main\data\raw\api_mashup\active_mashups_data.txt")
txtcontent = txtfile.read()
jsondata = json.loads(txtcontent)

# print(len(jsondata))

titleList = []
numList = []

style_data = {}

for api in jsondata:
    if api != None:
        if (len(api["related_apis"]) > 1):
            style_data[api["title"]] = {"REST":0,"RPC":0,"FEED":0,"Streaming":0,"Indirect":0,"EMAIL/MESSAGING/FTP":0,"Unspecified":0}
            for related_api in api["related_apis"]:
                if related_api:
                    style = ""
                    for version in related_api["versions"]:
                        if style == "REST":
                            break
                        else:
                            style = version["style"]
                    style_data[api["title"]][style] += 1

df = pd.DataFrame.from_dict(style_data, orient='index')
df.to_csv("style_data.csv")






